CBank = window.CBank || {};
CBank.fn = CBank.prototype = {
	/**
	 * 初始化
	 */
	init : function() {
		return this;
	}

};

var ScrollPagenation = function(o) {
	this.hasNaxt = true;
	this.pageNumber = (o.pageNumber || "1") / 1 - 1;
	this.pageSize = o.pageSize || '8';

	this.scrollEl = o.scrollEl;
	this.height = o.height;

	var m = this;

	if (!m.scrollEl) {
		alert('请设置滑动元素');
	}

	if (!m.height || m.height / 1 <= 0) {
		alert('请设置欢动范围高度');
	}

	m.next = function() {
		o.loadUI(true);
		if (m.hasNaxt) {
			m.hasNaxt = false;
			m.pageNumber = m.pageNumber / 1 + 1;
			if (typeof o.nextPage == 'function') {
				o.nextPage({
					pageNumber : m.pageNumber,
					pageSize : m.pageSize,
					callbackFn : function(hasNaxt) {
						o.loadUI(false);
						m.hasNaxt = hasNaxt;
					}
				});
			} else {
				alert('未定义分页啦数据核心函数');
			}
		}
	};

   m.scrollEl.scroll(function() {
		var top = m.scrollEl.scrollTop();
		if(CBank.scrollDisable){
			m.scrollEl.scrollTop(CBank.scrollDisable_top);
			return false;
		}
		var height = m.scrollEl.height() - m.height;
		if ((top + 66) > height) {
			if (m.hasNaxt) {
				o.loadUI(true);
				m.next();
			}
		}
	});

	m.init = function() {
		m.hasNaxt = true;
		m.pageNumber = (o.pageNumber || "1") / 1 - 1;
		m.pageSize = o.pageSize || '8';
		m.next();
	};

	m.next();
};
var page = function(totalCount, pageSize) {
	var page = 0;
	if (totalCount == 0) {
		return page;
	}
	if (totalCount % pageSize == 0) {
		page = totalCount / pageSize;
		page = page == 0 ? 1 : page;
	} else {
		page = parseInt(totalCount / pageSize) + 1;
	}
	return page;
};

window._ScrollPagenation = true;